package com.niit.bigdata;

import com.niit.bigdata.entity.Order;
import com.niit.bigdata.service.KafkaProducerService;
import com.niit.bigdata.service.RedisService;
import com.niit.bigdata.util.OrderGenerator;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class OrderScheduledTask {
    final private KafkaProducerService kafkaProducerService;
    final private RedisService redisService;

    OrderScheduledTask(KafkaProducerService kafkaProducerService, RedisService redisService) {
        this.kafkaProducerService = kafkaProducerService;
        this.redisService = redisService;
    }

    @Scheduled(fixedRate = 1000)
    public void printCurrentTime() throws Exception {
        Order order = OrderGenerator.generateRandomOrder();
        redisService.updateTotal();
        this.kafkaProducerService.sendMessage("orders","order", order.toString());
    }
}
